using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace sharpTV.Entities
{
	/// <summary>
	/// Strongly-typed collection for the Timeline class.
	/// </summary>
    [Serializable]
	public partial class TimelineCollection : ActiveList<Timeline, TimelineCollection>
	{	   
		public TimelineCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>TimelineCollection</returns>
		public TimelineCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                Timeline o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the sharpTV_Timelines table.
	/// </summary>
	[Serializable]
	public partial class Timeline : ActiveRecord<Timeline>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Timeline()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public Timeline(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public Timeline(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public Timeline(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("sharpTV_Timelines", TableType.Table, DataService.GetInstance("sharpTVSubSonicProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarTimelineId = new TableSchema.TableColumn(schema);
				colvarTimelineId.ColumnName = "TimelineId";
				colvarTimelineId.DataType = DbType.Int32;
				colvarTimelineId.MaxLength = 0;
				colvarTimelineId.AutoIncrement = true;
				colvarTimelineId.IsNullable = false;
				colvarTimelineId.IsPrimaryKey = true;
				colvarTimelineId.IsForeignKey = false;
				colvarTimelineId.IsReadOnly = false;
				colvarTimelineId.DefaultSetting = @"";
				colvarTimelineId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTimelineId);
				
				TableSchema.TableColumn colvarTimelineUId = new TableSchema.TableColumn(schema);
				colvarTimelineUId.ColumnName = "TimelineUId";
				colvarTimelineUId.DataType = DbType.Guid;
				colvarTimelineUId.MaxLength = 0;
				colvarTimelineUId.AutoIncrement = false;
				colvarTimelineUId.IsNullable = true;
				colvarTimelineUId.IsPrimaryKey = false;
				colvarTimelineUId.IsForeignKey = false;
				colvarTimelineUId.IsReadOnly = false;
				
						colvarTimelineUId.DefaultSetting = @"(newid())";
				colvarTimelineUId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTimelineUId);
				
				TableSchema.TableColumn colvarDateX = new TableSchema.TableColumn(schema);
				colvarDateX.ColumnName = "Date";
				colvarDateX.DataType = DbType.DateTime;
				colvarDateX.MaxLength = 0;
				colvarDateX.AutoIncrement = false;
				colvarDateX.IsNullable = true;
				colvarDateX.IsPrimaryKey = false;
				colvarDateX.IsForeignKey = false;
				colvarDateX.IsReadOnly = false;
				
						colvarDateX.DefaultSetting = @"(getdate())";
				colvarDateX.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateX);
				
				TableSchema.TableColumn colvarStartTime = new TableSchema.TableColumn(schema);
				colvarStartTime.ColumnName = "StartTime";
				colvarStartTime.DataType = DbType.DateTime;
				colvarStartTime.MaxLength = 0;
				colvarStartTime.AutoIncrement = false;
				colvarStartTime.IsNullable = true;
				colvarStartTime.IsPrimaryKey = false;
				colvarStartTime.IsForeignKey = false;
				colvarStartTime.IsReadOnly = false;
				colvarStartTime.DefaultSetting = @"";
				colvarStartTime.ForeignKeyTableName = "";
				schema.Columns.Add(colvarStartTime);
				
				TableSchema.TableColumn colvarEndTime = new TableSchema.TableColumn(schema);
				colvarEndTime.ColumnName = "EndTime";
				colvarEndTime.DataType = DbType.DateTime;
				colvarEndTime.MaxLength = 0;
				colvarEndTime.AutoIncrement = false;
				colvarEndTime.IsNullable = true;
				colvarEndTime.IsPrimaryKey = false;
				colvarEndTime.IsForeignKey = false;
				colvarEndTime.IsReadOnly = false;
				colvarEndTime.DefaultSetting = @"";
				colvarEndTime.ForeignKeyTableName = "";
				schema.Columns.Add(colvarEndTime);
				
				TableSchema.TableColumn colvarEventCount = new TableSchema.TableColumn(schema);
				colvarEventCount.ColumnName = "EventCount";
				colvarEventCount.DataType = DbType.Int16;
				colvarEventCount.MaxLength = 0;
				colvarEventCount.AutoIncrement = false;
				colvarEventCount.IsNullable = true;
				colvarEventCount.IsPrimaryKey = false;
				colvarEventCount.IsForeignKey = false;
				colvarEventCount.IsReadOnly = false;
				
						colvarEventCount.DefaultSetting = @"((0))";
				colvarEventCount.ForeignKeyTableName = "";
				schema.Columns.Add(colvarEventCount);
				
				TableSchema.TableColumn colvarSpotCount = new TableSchema.TableColumn(schema);
				colvarSpotCount.ColumnName = "SpotCount";
				colvarSpotCount.DataType = DbType.Int16;
				colvarSpotCount.MaxLength = 0;
				colvarSpotCount.AutoIncrement = false;
				colvarSpotCount.IsNullable = true;
				colvarSpotCount.IsPrimaryKey = false;
				colvarSpotCount.IsForeignKey = false;
				colvarSpotCount.IsReadOnly = false;
				
						colvarSpotCount.DefaultSetting = @"((0))";
				colvarSpotCount.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSpotCount);
				
				TableSchema.TableColumn colvarCreationDate = new TableSchema.TableColumn(schema);
				colvarCreationDate.ColumnName = "CreationDate";
				colvarCreationDate.DataType = DbType.DateTime;
				colvarCreationDate.MaxLength = 0;
				colvarCreationDate.AutoIncrement = false;
				colvarCreationDate.IsNullable = true;
				colvarCreationDate.IsPrimaryKey = false;
				colvarCreationDate.IsForeignKey = false;
				colvarCreationDate.IsReadOnly = false;
				
						colvarCreationDate.DefaultSetting = @"(getdate())";
				colvarCreationDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreationDate);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["sharpTVSubSonicProvider"].AddSchema("sharpTV_Timelines",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("TimelineId")]
		[Bindable(true)]
		public int TimelineId 
		{
			get { return GetColumnValue<int>(Columns.TimelineId); }
			set { SetColumnValue(Columns.TimelineId, value); }
		}
		  
		[XmlAttribute("TimelineUId")]
		[Bindable(true)]
		public Guid? TimelineUId 
		{
			get { return GetColumnValue<Guid?>(Columns.TimelineUId); }
			set { SetColumnValue(Columns.TimelineUId, value); }
		}
		  
		[XmlAttribute("DateX")]
		[Bindable(true)]
		public DateTime? DateX 
		{
			get { return GetColumnValue<DateTime?>(Columns.DateX); }
			set { SetColumnValue(Columns.DateX, value); }
		}
		  
		[XmlAttribute("StartTime")]
		[Bindable(true)]
		public DateTime? StartTime 
		{
			get { return GetColumnValue<DateTime?>(Columns.StartTime); }
			set { SetColumnValue(Columns.StartTime, value); }
		}
		  
		[XmlAttribute("EndTime")]
		[Bindable(true)]
		public DateTime? EndTime 
		{
			get { return GetColumnValue<DateTime?>(Columns.EndTime); }
			set { SetColumnValue(Columns.EndTime, value); }
		}
		  
		[XmlAttribute("EventCount")]
		[Bindable(true)]
		public short? EventCount 
		{
			get { return GetColumnValue<short?>(Columns.EventCount); }
			set { SetColumnValue(Columns.EventCount, value); }
		}
		  
		[XmlAttribute("SpotCount")]
		[Bindable(true)]
		public short? SpotCount 
		{
			get { return GetColumnValue<short?>(Columns.SpotCount); }
			set { SetColumnValue(Columns.SpotCount, value); }
		}
		  
		[XmlAttribute("CreationDate")]
		[Bindable(true)]
		public DateTime? CreationDate 
		{
			get { return GetColumnValue<DateTime?>(Columns.CreationDate); }
			set { SetColumnValue(Columns.CreationDate, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid? varTimelineUId,DateTime? varDateX,DateTime? varStartTime,DateTime? varEndTime,short? varEventCount,short? varSpotCount,DateTime? varCreationDate)
		{
			Timeline item = new Timeline();
			
			item.TimelineUId = varTimelineUId;
			
			item.DateX = varDateX;
			
			item.StartTime = varStartTime;
			
			item.EndTime = varEndTime;
			
			item.EventCount = varEventCount;
			
			item.SpotCount = varSpotCount;
			
			item.CreationDate = varCreationDate;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varTimelineId,Guid? varTimelineUId,DateTime? varDateX,DateTime? varStartTime,DateTime? varEndTime,short? varEventCount,short? varSpotCount,DateTime? varCreationDate)
		{
			Timeline item = new Timeline();
			
				item.TimelineId = varTimelineId;
			
				item.TimelineUId = varTimelineUId;
			
				item.DateX = varDateX;
			
				item.StartTime = varStartTime;
			
				item.EndTime = varEndTime;
			
				item.EventCount = varEventCount;
			
				item.SpotCount = varSpotCount;
			
				item.CreationDate = varCreationDate;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn TimelineIdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn TimelineUIdColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn DateXColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn StartTimeColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn EndTimeColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn EventCountColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn SpotCountColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn CreationDateColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string TimelineId = @"TimelineId";
			 public static string TimelineUId = @"TimelineUId";
			 public static string DateX = @"Date";
			 public static string StartTime = @"StartTime";
			 public static string EndTime = @"EndTime";
			 public static string EventCount = @"EventCount";
			 public static string SpotCount = @"SpotCount";
			 public static string CreationDate = @"CreationDate";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
